package com.mdxq.mall.order.service.impl;

import com.mdxq.mall.order.client.ProductServiceClient;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.mdxq.mall.order.entity.OrderReturnApply;
import com.mdxq.mall.order.mapper.OrderReturnApplyMapper;
import com.mdxq.mall.order.service.OrderReturnApplyService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单退货申请 服务层实现。
 *
 * @author zdy
 * @since 2025-01-19
 */
@Service
public class OrderReturnApplyServiceImpl extends ServiceImpl<OrderReturnApplyMapper, OrderReturnApply>  implements OrderReturnApplyService{
    @Autowired
    private ProductServiceClient productServiceClient;
    @Override
    @GlobalTransactional
//    @Transactional该注解的生效范围是本地事务，无法控制商品数据库的提交和回滚
    public boolean updateById(OrderReturnApply entity,boolean ignoreNulls) {
        if (entity.getStatus()==2){
            OrderReturnApply apply = super.getById(entity.getId());
            //修改商品库中的商品表
            productServiceClient.restocking(apply.getProductId(),apply.getProductCount());
        }
        //修改订单库中的退货表
        return super.updateById(entity,ignoreNulls);
    }
}
